home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_11_09
/
1109090a
< prev
next >
Wrap
Text File
|
1993-07-06
|
1KB
|
34 lines
typedef struct resdesc
{
float out1, out2; /* filter state variables */
float a1, b1, b2; /* filter coefficients */
} resdesc;
static void Avoid_Underflow(resdesc *o)
{
/* clamp state variables */
if(o->out1>-0.0000000001f
&& o->out1<0.0000000001f)
o->out1 = 0.0f;
if(o->out2>-0.0000000001f
&& o->out2<0.0000000001f)
o->out2 = 0.0f;
}
/* assumes coefficients are constant throughout block */
void Resonator(resdesc *f , int n, float *out,
int stride, float *in, int istride )
{
float ym;
int j;
j=0;
for(j=0;j<n;++j)
{
ym = f->b1 * f->out1 + f->b2 * f->out2
+ f->a1 * in[j*istride];
f->out2 = f->out1;
f->out1 = ym;
out[j*stride] = ym;
}
Avoid_Underflow(f);
}